package cn.didi.feidi.androidorder.fragment;

import android.os.Bundle;
import android.view.View;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.Marker;

/**
 * Created by jinxiong on 2017/8/30.
 */

public abstract class BaseMapFragment extends FeidiBaseFragment
        implements AMap.InfoWindowAdapter, AMap.OnMarkerClickListener, AMapLocationListener {

    protected AMap mAMap;//mapView 管理类
    protected MapView mMapView;//地图view
    protected AMapLocationClient mClient;//定位相关
    protected AMapLocationClientOption mOption;//定位配置类

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        return false;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mClient = new AMapLocationClient(getActivity().getApplicationContext());
        mOption = new AMapLocationClientOption();
        getPermissionBlankMethod();
    }

    protected abstract void getPermissionBlankMethod();

    @Override
    public void onPause() {
        super.onPause();
        if (mMapView != null) {
            mMapView.onPause();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mMapView != null) {
            mMapView.onResume();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mMapView != null) {
            mMapView.onDestroy();
        }

        if (null != mClient) {
//            mClient.setLocationListener(null);
            mClient.stopLocation();
            mClient.onDestroy();
            mClient = null;
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mMapView != null) {
            mMapView.onSaveInstanceState(outState);
        }
    }
}
